//
// Created by lau on 2019-10-18.
//

#ifndef VIDEOEFFECT_GRAYFILTER_H
#define VIDEOEFFECT_GRAYFILTER_H


#include <ve_core.h>
#include "../context.h"
#include "../glutils/program.h"


namespace VideoEffect {

    class Context;

    class GrayFilter {

    private:

        const char *VERTEXT_SHADER =
                "attribute vec2 aPosition;\n"
                "attribute vec2 aTextureCoord;\n"
                "varying vec2 vTexCoord;\n"
                "void main()\n"
                "{\n"
                "   gl_Position = vec4(aPosition, 0, 1.0);\n"
                "   vTexCoord = aTextureCoord;\n"
                "}\n";

        const char *FRAGMENT_SHADER =
                "precision mediump float;\n"
                "varying vec2 vTexCoord;\n"
                "uniform sampler2D uTexture0;\n"
                "void main()\n"
                "{\n"
                "   mediump vec3 rgb = texture2D(uTexture0, vTexCoord).rgb;\n"
//                "   float average = (rgb.r * 0.2126 + rgb.g * 0.7152 + rgb.b * 0.0722);\n"
//                "   lowp float average = (rgb.r + rgb.g + rgb.b) / 3.0;\n"
//                "   gl_FragColor = vec4(average, average, average, 1.0);\n"
                "   gl_FragColor = vec4(rgb, 1.0);\n"
                "}\n";

        Program *mProgram;

        Context *mContext;

    public:
        void initFilter();

        void rendFrame(_VE_TEXTURE *textureIn, _VE_TEXTURE *textureOut);

        void setContext(Context *context);

        GLuint createTexture(int width, int height, VEUInt32 format, VEUInt32 target);
    };


}
#endif //VIDEOEFFECT_GRAYFILTER_H
